import Ember from 'ember';
import BaseBusiness from '../base-business';

export default BaseBusiness.extend({
  queryParams: {
      id: {
          refreshModel: true
      },
      editMode: {
          refreshModel: true
      },
      add:{
        refreshModel:true
      }
  },
  header_title:'入住信息',
  model(){
    return{};
  },
  setupController(controller, model){
    this._super(controller, model);
    let _self = this;
    var editMode=this.getCurrentController().get('editMode');
    var id=this.getCurrentController().get('id');
    if(editMode=='edit'){
      controller.set('detailEdit',false);
      this.store.findRecord('customerbusinessflow',id).then(function(customerbusinessflowInfo){
        controller.set('customerbusinessflowInfo',customerbusinessflowInfo);
        _self.store.query('nursingproject',{filter:{customer:{id:customerbusinessflowInfo.get('customer.id')}}}).then(function(project){
          controller.set('project',project.get('firstObject'));
          console.log('方案价格：',controller.get('project.price'));
        });
        controller.set('customer',customerbusinessflowInfo.get('customer'));
      });
    }else{
      this.store.findRecord('customerbusinessflow',id).then(function(customerbusinessflowInfo){
        controller.set('customerbusinessflowInfo',customerbusinessflowInfo);
        _self.store.query('nursingproject',{filter:{customer:{id:customerbusinessflowInfo.get('customer.id')}}}).then(function(project){
          controller.set('project',project.get('firstObject'));
          console.log('方案价格：',controller.get('project.price'));
        });
      });
      console.log("add:",controller.get('add'));
      controller.set('detailEdit',true);
    }
    this.store.query('bed',{filter:{status:{typecode:'bedStatusIdle'}}}).then(function(bedList){
      bedList.forEach(function(bed){
        bed.set('namePinyin',pinyinUtil.getFirstLetter(bed.get("name")));
      });
      controller.set('bedList',bedList);
    });
    this.store.query('user',{}).then(function(staffList){
      staffList.forEach(function(staff){
        staff.set('namePinyin',pinyinUtil.getFirstLetter(staff.get("name")));
      });
      controller.set('staffList',staffList);
    });
  }
});
